Skip to content

Fix wake lock re-acquisition on visibility change#25

Merged
willchan merged 2 commits intomainfrom
claude/fix-workout-screen-wake-lock-XtB8p
Mar 8, 2026
Merged

Fix wake lock re-acquisition on visibility change#25
willchan merged 2 commits intomainfrom
claude/fix-workout-screen-wake-lock-XtB8p

Conversation

@willchan
Copy link
Owner

@willchan willchan commented Mar 8, 2026

Summary

This PR fixes the wake lock re-acquisition logic to properly handle visibility changes while preventing unnecessary re-requests after explicit release.

Key Changes

  • Added wakeLockActive flag to track whether wake lock should be maintained across visibility changes
  • Set wakeLockActive = true when requestWakeLock() is called
  • Set wakeLockActive = false when releaseWakeLock() is called
  • Updated the visibilitychange event listener to re-acquire wake lock only when the page becomes visible AND wakeLockActive is true
  • Added comprehensive e2e tests to verify wake lock behavior during visibility changes and after explicit release

Implementation Details

The fix introduces a state flag (wakeLockActive) that distinguishes between:

  1. Temporary loss (browser releases sentinel on visibility change) → re-acquire if flag is true
  2. Explicit release (user navigates away) → don't re-acquire since flag is false

This ensures the wake lock is properly maintained during app switching (e.g., on iOS) while respecting user navigation that should release the lock.

https://claude.ai/code/session_01MgxBE65U2FSemXB1CKtdZF

claude added 2 commits March 8, 2026 21:54
The wake lock was requested when entering the workout screen, but the
visibilitychange handler never re-acquired it after the page became
visible again. On iOS, switching apps releases the wake lock, so the
screen would time out after returning to the workout. Track whether a
wake lock is actively wanted and re-request it on visibility change.

https://claude.ai/code/session_01MgxBE65U2FSemXB1CKtdZF
…e test

The test was flaky because it reloaded the page immediately after
checking the intersperse checkbox, without waiting for the async
putSettings() IndexedDB write to complete. Add a waitForFunction
that reads directly from IndexedDB to confirm the write landed.

https://claude.ai/code/session_01MgxBE65U2FSemXB1CKtdZF
@willchan willchan merged commit a41d5b1 into main Mar 8, 2026
1 check passed
@willchan willchan deleted the claude/fix-workout-screen-wake-lock-XtB8p branch March 8, 2026 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants